package com.yanq.liancar.adapter;
/*
 *  @创建者     liyan
 *  @创建时间   2018/9/13  11:02
 *  @描述       ${TODO}
 */


import android.content.Context;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.vondear.rxtool.RxActivityTool;
import com.yanq.liancar.R;
import com.yanq.liancar.activity.SmallBEJGoodsListActivity;
import com.yanq.liancar.activity.SmallBGoodsListActivity;
import com.yanq.liancar.bean.SelectClassifyBean;

import java.util.List;

import static com.vondear.rxtool.RxImageTool.dip2px;

public class SmallSelectClassAdapter extends RecyclerView.Adapter<SmallSelectClassAdapter.MyViewHolder> {
    private Context mContext;
    private List<SelectClassifyBean.DataBean.B2SmallClassifiesBean>mList;
    private OnItemClickListener mOnItemClickListener;
    private int id;

    public SmallSelectClassAdapter(Context context,List<SelectClassifyBean.DataBean.B2SmallClassifiesBean>mList,int Bid){
        this.mContext=context;
        this.mList=mList;
        this.id=Bid;
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.small_selectclass,parent,false);
        Resources resources = mContext.getResources();
        DisplayMetrics dm = resources.getDisplayMetrics();
        RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams((dm.widthPixels - dip2px(20)) / 3, ViewGroup.LayoutParams.WRAP_CONTENT);
        view.setLayoutParams(lp);
        MyViewHolder viewHolder=new MyViewHolder(view);
        return viewHolder;

    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, final int position) {
        if (mList!=null){
            holder.mTextView.setText(mList.get(position).getSmall_classifyname());
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Bundle bundle = new Bundle();
                    bundle.putString("where", "SmallSelectClassAdapter");
                    bundle.putInt("Bid", id);
                    bundle.putInt("Sid", mList.get(position).getSmall_classify());
                    RxActivityTool.skipActivity(mContext, SmallBEJGoodsListActivity.class, bundle);
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return (mList == null ? 0 : mList.size());
    }

    class MyViewHolder extends RecyclerView.ViewHolder{
        TextView mTextView;
        public MyViewHolder(View itemView) {
            super(itemView);
            mTextView=itemView.findViewById(R.id.class_textview);
        }
    }

    public interface OnItemClickListener {
        void onItemClick(View view);
    }
}
